package com.example.literaturesystem.dao.team;

import com.example.literaturesystem.domain.base.BaseModel;
import com.example.literaturesystem.domain.team.Team;
import com.example.literaturesystem.domain.user.User;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("teamDao")
public interface ITeamDao {//dao 层定义方法接口，然后在service层和serviceimpl层实现接口方法，从而达到操作数据库的目的。
    @Select("<script>SELECT  * FROM teamtable WHERE 1=1\n" +
            "<if test=\"teamNo!=null and teamNo!=''\">\n" +
            "AND TeamNo=#{teamNo}\n" +
            "</if>\n" +
            "<if test=\"userName!=null and userName!=''\">\n" +
            "AND UserName=#{userName}\n" +
            "</if>\n" +
            "<if test=\"password!=null and password!=''\">\n" +
            "AND Password=#{password}\n" +
            "</if>\n" +
            "<if test=\"teamName!=null and teamName!=''\">\n" +
            "AND TeamName=#{teamName}\n" +
            "</if>\n" +
            "<if test=\"category!=null and category!=''\">\n" +
            "AND Category=#{category}\n" +
            "</if>\n" +
            "<if test=\"discipline!=null and discipline!=''\">\n" +
            " AND Discipline=#{discipline}\n" +
            "</if>" +
            "<if test=\"currentNum!=null and currentNum!=''\">\n" +
            "AND CurrentNum=#{currentNum}\n" +
            "</if>\n" +
            "<if test=\"maxNum!=null and maxNum!=''\">\n" +
            "AND MaxNum=#{maxNum}\n" +
            "</if>\n" +
            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
            "AND UserEmail=#{userEmail}\n" +
            "</if>\n" +
            "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
            "AND TeamEmail=#{teamEmail}\n" +
            "</if>\n" +
            "<if test=\"userRole!=null and userRole!=''\">\n" +
            "AND UserRole=#{userRole}\n" +
            "</if>\n" +
            "<if test=\"date!=null and date!=''\">\n" +
            "AND Date=#{date}\n" +
            "</if>\n" +
            "<if test=\"note!=null and note!=''\">\n" +
            "AND Note=#{note}\n" +
            "</if>\n" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            "AND IfUse=#{ifuse}\n" +
            "</if>\n" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            "AND DateTime=#{dateTime}\n" +
            "</if>\n" +
            "</script>")
    List<Team> query(BaseModel baseModel);

    @Insert("<script>" +
            " INSERT INTO teamtable (TeamNo,UserName,Password, TeamName,Category,Discipline," +
            " CurrentNum, MaxNum, UserEmail, TeamEmail, UserRole, Date, Note, DateTime, IfUse,State)" +
            " VALUES (#{teamNo},#{userName},#{password},#{teamName},#{category},#{discipline}," +
            " #{currentNum},#{maxNum},#{userEmail},#{teamEmail},#{userRole},#{date},#{note},#{dateTime},#{ifuse},#{state})" +
            "</script>")
    int insert(BaseModel baseModel);

    @Update("<script>" +
            "UPDATE teamtable\n" +
            " <trim prefix=\"SET\" suffixOverrides=\",\">\n" +
            "<if test=\"userName!=null and userName!=''\">\n" +
            " UserName=#{userName},\n" +
            "</if>\n" +
            "<if test=\"password!=null and password!=''\">\n" +
            " Password=#{password},\n" +
            "</if>\n" +
            "<if test=\"teamName!=null and teamName!=''\">\n" +
            " TeamName=#{teamName},\n" +
            "</if>\n" +
            "<if test=\"category!=null and category!=''\">\n" +
            " Category=#{category},\n" +
            "</if>" +
            "<if test=\"discipline!=null and discipline!=''\">\n" +
            " Discipline=#{discipline},\n" +
            "</if>" +
            "<if test=\"currentNum!=null and currentNum!=''\">\n" +
            " CurrentNum=#{currentNum},\n" +
            "</if>" +
            "<if test=\"maxNum!=null and maxNum!=''\">\n" +
            " MaxNum=#{maxNum},\n" +
            "</if>" +
            "<if test=\"userEmail!=null and userEmail!=''\">\n" +
            " UserEmail=#{userEmail},\n" +
            "</if>" +
            "<if test=\"teamEmail!=null and teamEmail!=''\">\n" +
            " TeamEmail=#{teamEmail},\n" +
            "</if>" +
            "<if test=\"userRole!=null and userRole!=''\">\n" +
            " UserRole=#{userRole},\n" +
            "</if>" +
            "<if test=\"date!=null and date!=''\">\n" +
            " Date=#{date},\n" +
            "</if>" +
            "<if test=\"note!=null and note!=''\">\n" +
            " Note=#{note,}\n" +
            "</if>" +
            "<if test=\"dateTime!=null and dateTime!=''\">\n" +
            " DateTime=#{dateTime},\n" +
            "</if>" +
            "<if test=\"ifuse!=null and ifuse!=''\">\n" +
            " IfUse=#{ifuse}\n" +
            "</if>" +
            "<if test=\"state!=null and state!=''\">\n" +
            " State=#{state},\n" +
            "</if>" +
            " </trim>" +
            "WHERE TeamNo=#{teamNo}" +
            "</script>")
    int update(BaseModel baseModel);
    
    @Delete("<script>" +
    		"delete from teamtable"+
    		" WHERE TeamNo=#{teamNo}"+
    		"</script>")
    int delete(BaseModel baseModel);
    
}
